#include "cpu/exec/template-start.h"

#define	instr	adc

extern CPU_state cpu;

static void do_execute() {
	uint32_t i, count = 0;
	bool cf, of, af;
	op_dest->val += cpu.CF;
	cf = (cpu.CF == 1 && op_dest->val == 0);
	of = (cpu.CF == 1 && MSB(op_dest->val - 1) == 0 && MSB(op_dest->val) == 1);
	af = (cpu.CF == 1 && (op_dest->val & 0xf) == 0);
	DATA_TYPE temp = op_src->val + op_dest->val;
	OPERAND_W(op_dest, temp);

	cpu.ZF = (temp == 0);
	cpu.SF = MSB(temp);
	cpu.OF = (of || ((MSB(op_dest->val) == MSB(op_src->val))
			&& (MSB(temp) != MSB(op_dest->val))));
	cpu.CF = (cf || (temp < op_src->val) || (temp < op_dest->val));
	cpu.AF = (af || ((temp & 0xf) < (op_src->val & 0xf))
			|| ((temp & 0xf) < (op_dest->val & 0xf)));
	temp &= 0xff;
	for (i = 0; i < 8; i++, temp >>= 1) {
		count += (temp & 0x1);
	}
	cpu.PF = (count % 2 == 0);

	print_asm_template2();
}

make_instr_helper(i2a)
make_instr_helper(i2rm)
make_instr_helper(r2rm)
make_instr_helper(rm2r)

#if	DATA_BYTE == 4 || DATA_BYTE == 2
make_instr_helper(si2rm)
/*make_helper(concat(adc_i2rm_b2_, SUFFIX)) {
	int8_t i, count = 0;
	bool cf, of, af;
	DATA_TYPE_S s;
	DATA_TYPE temp;
	int len = 1 + concat(decode_rm_, SUFFIX)(eip + 1);
	i = instr_fetch(eip + len, 1);
	len += 1;
	s = (DATA_TYPE_S) i;
	op_src->val += cpu.CF;
	cf = (cpu.CF == 1 && op_src->val == 0);
	of = (cpu.CF == 1 && MSB(op_src->val - 1) == 0 && MSB(op_src->val) == 1);
	af = (cpu.CF == 1 && (op_src->val & 0xf) == 0);
	temp = s + op_src->val;
	OPERAND_W(op_src, temp);
	
	cpu.ZF = (temp == 0);
	cpu.SF = MSB(temp);
	cpu.OF = (of || ((MSB(s) == MSB(op_src->val))
			&& (MSB(temp) != MSB(s))));
	cpu.CF = (cf || (temp < op_src->val) || (temp < s));
	cpu.AF = (af || ((temp & 0xf) < (op_src->val & 0xf))
			|| ((temp & 0xf) < (s & 0xf)));
	temp &= 0xff;
	for (i = 0; i < 8; i++, temp >>= 1) {
		count += (temp & 0x1);
	}
	cpu.PF = (count % 2 == 0);

	print_asm("adc" str(SUFFIX) " $%x,%s", s, op_src->str);
	return len;
}*/
#endif

#include "cpu/exec/template-end.h"
